/**
 * @description: 单例
 * @param {*} className 选定类
 * @param {*} silent 是否开启静默模式
 * @return {*}
 */
export function singleIns(className, silent = true) {
  let ins
  let tag = false
  return new Proxy(className, {
    construct(target, args) {
      if (tag && !silent) {
        throw new Error('Cannot be instantiated repeatedly')
      }
      if (!ins) {
        ins = new className(...args)
        tag = true
      }
      return ins
    }
  })
}